package mime;

import org.apache.ibatis.cache.Cache;
import org.apache.ibatis.cache.decorators.BlockingCache;
import org.junit.jupiter.api.Test;

/**
 * 广州奥凯信息咨询有限公司
 * <p>
 * 本源代码由《项目一组》及其作者共同所有，未经版权持有者的事先书面授权，
 * 不得使用、复制、修改、合并、发布、分发和/或销售本源代码的副本。
 *
 * @copyright Copyright (广州奥凯信息咨询有限公司) 2019-2022. all rights reserved.
 */

public class DemoOfBlockingCache {

  @Test
  public void t(){
    BlockingCache blockingCache = new BlockingCache(new Cache() {
      @Override
      public String getId() {
        return null;
      }

      @Override
      public void putObject(Object key, Object value) {
      }

      @Override
      public Object getObject(Object key) {
        if (key.equals("k2")){
          return "13";
        }
        return null;
      }

      @Override
      public Object removeObject(Object key) {
        return null;
      }

      @Override
      public void clear() {

      }

      @Override
      public int getSize() {
        return 0;
      }
    });
    System.out.println(blockingCache.getObject("k1"));
    System.out.println(blockingCache.getObject("k2"));

    Runnable runnable = () -> {

      System.out.println(blockingCache.getObject("k2"));
      System.out.println("44__1");
      System.out.println(blockingCache.getObject("k1"));
      System.out.println("44");
    };
    new Thread(runnable).start();

    Runnable runnable2 = () -> {

      System.out.println(blockingCache.getObject("k2"));
      System.out.println("22_1");
      System.out.println(blockingCache.getObject("k1"));
      System.out.println("22");
    };
    new Thread(runnable2).start();

    while (true){}
  }
}
